/* eslint-disable no-param-reassign */
import { reactive } from 'vue'

export interface IPillar {
  height: 1500 | 2000 | 2200
  diameter: [60, 60] | [40, 60]
  color: 'BLK' | 'YLW' | 'RAL7035' | 'RAL5017' | 'RAL3000' | 'RAL9016'
  hole: boolean
}

export const Pillar: IPillar = {
  height: 2000,
  diameter: [40, 60],
  color: 'YLW',
  hole: true
}

export class PillarClass implements IPillar {
  points: number[]

  angle: number

  height: 1500 | 2000 | 2200

  diameter: [60, 60] | [40, 60]

  color: 'BLK' | 'YLW' | 'RAL7035' | 'RAL5017' | 'RAL3000' | 'RAL9016'

  hole: boolean

  constructor(
    points: number[] = [0, 0],
    angle: number = 0,
    height: 1500 | 2000 | 2200 = 2000,
    diameter: [60, 60] | [40, 60] = [40, 60],
    color: 'BLK' | 'YLW' | 'RAL7035' | 'RAL5017' | 'RAL3000' | 'RAL9016' = 'YLW',
    hole: boolean = true
  ) {
    this.height = height
    this.diameter = diameter
    this.color = color
    this.hole = hole
    this.points = points
    this.angle = angle
  }

  getName() {
    return `KKPT-Y-${this.diameter[0]}x${this.diameter[1]}x${this.height}-${this.color}-SET`
  }

  getProtectiveRingName() {
    return `KKPT-${this.diameter[0]}x${this.diameter[1]}-EZ-SET`
  }

  getShieldName() {
    return `KKPT-FHZ-${this.diameter[0]}x${this.diameter[1]}-BLK-SET`
  }

  static fromString(name: string) {
    const str = name.split('-')
    if (str.length !== 5) return null
    return {
      model: name,
      type: str[2],
      color: str[3]
    }
  }
}

export function createPillar() {
  return reactive(Pillar)
}

export function createPillarAction(pillar: IPillar) {
  return {
    updateHeight: (height: 1500 | 2000 | 2200) => {
      pillar.height = height
    },
    updateDiameter: (diameter: [60, 60] | [40, 60]) => {
      pillar.diameter = diameter
    },
    updateColor: (color: 'BLK' | 'YLW' | 'RAL7035' | 'RAL5017' | 'RAL3000' | 'RAL9016' = 'YLW') => {
      pillar.color = color
    },
    updateHole: (hole: boolean) => {
      pillar.hole = hole
    }
  }
}
